package com.itheima.a01mystream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.stream.Stream;

public class StreamDemo2 {
    public static void main(String[] args) {
        //各种集合，数组，零散数据获取stream流的方法

        //1.单列集合获取stream流的方法
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list,"a","q","w","e","r","t");

        list.stream().forEach(s->System.out.println(s));


        //2.双列集合获取stream流的方法
        HashMap<String,String> hm = new HashMap<>();
        hm.put("A","a");
        hm.put("B","b");
        hm.put("C","c");
        hm.put("D","d");
        //先转为单列集合再进行操作
        hm.entrySet().stream().forEach(s->System.out.println(s));


        //数组获取stream流
        //需要使用到Arrays工具类的steam方法
        String[] arr={"a","b","c","d","e","f","g","h"};
        int[] arr2={1,2,3,4,5,6,7,8,9};
        Arrays.stream(arr2).forEach(s->System.out.println(s));


        //杂乱数据获取stream流（要求数据类型一致）可以使用stream里面的of方法
        //细节：of里面是可变参数，也可以传数组，但传数组时要求数组内容是引用数据类型
        //否则会将整个一堆数据当成一个整体，并得到其地址值
        Stream.of(1,2,3,4,5).forEach(s->System.out.println(s));
        Stream.of(arr2).forEach(s->System.out.println(s));


    }
}
